<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Creating and Populating a New DataTable</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Creating and Populating a New DataTable</span><hr />
<!--------------------------------------------------------------------------->

<asp:datagrid id="dgrResult" runat="server" />

<script language="vb" runat="server">

Sub Page_Load()

   'create a new empty Table object
   Dim objTable As New DataTable("NewTable")

   'define four columns (fields) within the table
   objTable.Columns.Add("ISBN", System.Type.GetType("System.String"))
   objTable.Columns.Add("Title", System.Type.GetType("System.String"))
   objTable.Columns.Add("PublicationDate", System.Type.GetType("System.DateTime"))
   objTable.Columns.Add("Quantity", System.Type.GetType("System.Int32"))

   'declare a variable to hold a DataRow object
   Dim objDataRow As DataRow

   'create a new DataRow object instance in this table
   objDataRow = objTable.NewRow()

   'and fill in the values
   objDataRow("ISBN") = "1234567800"
   objDataRow("Title") = "Professional Video Recorder Programming"
   objDataRow("PublicationDate") = "2001-03-01"
   objDataRow("Quantity") = 3956
   objTable.Rows.Add(objDataRow)

   'repeat to add two more rows
   objDataRow = objTable.NewRow()
   objDataRow("ISBN") = "1234567801"
   objDataRow("Title") = "Professional WAP Phone Programming"
   objDataRow("PublicationDate") = "2001-06-01"
   objDataRow("Quantity") = 29
   objTable.Rows.Add(objDataRow)

   objDataRow = objTable.NewRow()
   objDataRow("ISBN") = "1234567802"
   objDataRow("Title") = "Professional Radio Station Programming"
   objDataRow("PublicationDate") = "2001-04-01"
   objDataRow("Quantity") = 10456
   objTable.Rows.Add(objDataRow)

   'assign the DataTable's DefaultView object to the DataGrid control
   dgrResult.DataSource = objTable.DefaultView
   dgrResult.DataBind()  'and bind (display) the data

End Sub
</script>


<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>
